package com.sms.graduate.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sms.graduate.dao.SmsLeaveDao;
import com.sms.graduate.entity.SmsLeave;
import com.sms.graduate.entity.SmsUser;
import com.sms.graduate.service.SmsLeaveService;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
public class SmsLeaveServiceImpl extends ServiceImpl<SmsLeaveDao, SmsLeave> implements SmsLeaveService {


    @Override
    public Boolean addApply(SmsLeave smsLeave) {
        return this.save(smsLeave);
    }

    @Override
    public List<SmsLeave> selectLeaveApply(String userCode) {
        QueryWrapper<SmsLeave> queryWrapper = new QueryWrapper<>();
        queryWrapper
                .eq(SmsLeave.COL_USERCODE,userCode)
                .orderByDesc(SmsLeave.COL_ID);
        return this.list(queryWrapper);
    }

    @Override
    public Boolean passApply(Integer id) {
        UpdateWrapper<SmsLeave> updateWrapper = new UpdateWrapper<>();
        updateWrapper.set(SmsLeave.COL_STATUS,1)
                .set(SmsLeave.COL_RESULT,"通过")
                .eq(SmsLeave.COL_ID,id);
        return this.update(updateWrapper);
    }

    @Override
    public Boolean rejectApply(Integer id, String reject) {
        UpdateWrapper<SmsLeave> updateWrapper = new UpdateWrapper<>();
        updateWrapper.set(SmsLeave.COL_STATUS,2)
                .set(SmsLeave.COL_RESULT,reject)
                .eq(SmsLeave.COL_ID,id);
        return this.update(updateWrapper);
    }
}

